package com.example.bankend.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket api2() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("a");
    }

    @Bean
    public Docket api(Environment env) {

        Profiles profiles = Profiles.of("dev");
        boolean dev = env.acceptsProfiles(profiles);

        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
                .enable(dev)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.example.demo.controllers"))
                .build();
    }

    private ApiInfo apiInfo() {

        Contact contact = new Contact("阚思涵","https://localhost:8057","110347401@qq.com");

        return new ApiInfo(
                "小组作业",
                "背单词",
                "v1.0",
                "https://localhost:8080",
                contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList<>()
        );
    }
}
